import java.util.Objects;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-05-21
 * Time:23:14
 */
class Person{
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + id + '\'' +
                '}';
    }
    //@Override
    /*public boolean equals(Object obj){
        //判断obj参数是否为空
        if (obj == null){
            return false;
        }

        if(this == obj){
            return true;//有可能是对象之间的赋值，例如per2 == per1,那两个肯定是相等的
        }

        if(!(obj instanceof Person)){
            return false;
            //两个毫不相关的类的属性不能进行比较
            //obj根本就不是Person类的对象，所以肯定不相等
        }

        Person  tmp = (Person) obj;
        return this.id.equals(tmp.id);//Sting类型的equals
    }*/
   /* @Override
    public int hashCode(){
        return Objects.hash(id);
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
class Student{
}

public class Test {
    public static void func(Object obj) {
        System.out.println(obj);
    }

    public static void main(String[] args) {
        Person person1 = new Person("123");
        Person person2 = new Person("123");
        //将来对于他们我们想放在同一个位置上
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }
    /*public static void main(String[] args) {
        Person person1 = new Person("123");
        Person person2 = new Person("123");
        System.out.println(person1==person2);
        //System.out.println("equals未重写的 "+person1.equals(person2));
        System.out.println("equals重写后的 "+person1.equals(person2));
    }*/
}

